﻿using Coolvis.UI.Theme.Console;
using CPPEI.Coolzon.Event.NCL;
using CPPEI.Coolzon.Event.UI;
using CPPEI.Coolzon.ServiceProxy;
using CPPEI.Coolzon.UI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WEITSM.Theme.Default.Console
{
    /// <summary>
    /// Interaction logic for LoginView.xaml
    /// 用于做登录验证
    /// </summary>
    public partial class LoginView : View
    {
        /// <summary>
        /// 用户的账号
        /// </summary>
        public string UserAccount { get; set; }
        /// <summary>
        /// 用户的密码
        /// </summary>
        public string UserPassword { get; set; }

        /// <summary>
        /// 登陆类型
        /// </summary>
        public string SolutionSelectionMode { get; set; }

        private bool _isAutoLogin = false;

        public LoginViewLogic Logic { get; set; }

        public LoginView()
            : base()
        {
            InitializeComponent();

            Logic = new LoginViewLogic();
            Logic.Init(this);
            this.DataContext = this;
        }

        public LoginView(string userAccount, string userPassword)
            : base()
        {
            InitializeComponent();

            _ctlEditAccount.Text = userAccount;
            _ctlEditPassword.Password = UserPassword;
            _isAutoLogin = true;

            Logic = new LoginViewLogic();
            Logic.Init(this);
            this.DataContext = this;
        }

        protected override void OnActive()
        {
            base.OnActive();
            if (_isAutoLogin)
            {
                Logic.DoActionLogin(_ctlEditAccount.Text, _ctlEditPassword.Password);
            }
        }

        /// <summary>
        /// 点击登录按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ctlBtnOK_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(_ctlEditAccount.Text))
            {
                return;
            }
            
            _ctlBorderLogin.Visibility = System.Windows.Visibility.Hidden;
            _ctlBorderIndicator.Visibility = System.Windows.Visibility.Visible;

            Logic.DoActionLogin(_ctlEditAccount.Text, _ctlEditPassword.Password);
        }

        private void ctlBtnCancel_Click(object sender, RoutedEventArgs e)
        {
            Logic.DoActionCancel();
        }
    }
}
